package productlogic

import (
	"context"
	"zhongxc.cc/grpc-common/mall-product/types/product"
	"zhongxc.cc/mall-common/errs"
	"zhongxc.cc/mall-product/internal/domain"
	"zhongxc.cc/mall-product/internal/model"
	"zhongxc.cc/mall-product/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
	pmsSkuInfoDomain *domain.PmsSkuInfoDomain
}

func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
	return &CreateLogic{
		ctx:              ctx,
		svcCtx:           svcCtx,
		Logger:           logx.WithContext(ctx),
		pmsSkuInfoDomain: domain.NewPmsSkuInfoDomain(svcCtx.Db),
	}
}

func (l *CreateLogic) Create(in *product.CreateRequest) (*product.NoRes, error) {
	// todo: add your logic here and delete this line

	pmsSkuInfo := model.NewPmsSkuInfo()
	pmsSkuInfo.SkuDesc = in.SpuDescription
	pmsSkuInfo.SkuSubtitle = in.SupName

	err := l.pmsSkuInfoDomain.Save(context.Background(), pmsSkuInfo)
	if err != nil {
		return nil, errs.GrpcError(model.ErrorNewFail)
	}
	return &product.NoRes{}, nil
}
